﻿@{
    ViewBag.Title = "ResourceList";
    Layout = "~/Views/Shared/_BasicLayout.cshtml";
}
<script>
    $(function () {
        var loadingIndex;
        layui.use(['upload', 'form'], function () {
            var $ = layui.jquery, upload = layui.upload, form = layui.form;
            //多文件列表示例
            var demoListView = $('#demoList'),
                uploadListIns = upload.render({
                    elem: '#testList',
                    url: '/BD/File/Upload', //改成您自己的上传接口
                    accept: 'file',
                    multiple: true,
                    auto: false,
                    number: 5,
                    bindAction: '#testListAction',
                    choose: function (obj) {
                        var files = this.files = obj.pushFile(); //将每次选择的文件追加到文件队列
                        demoListView.html(" ");
                        for (var key in files) {
                            var tr = $(['<tr id="upload-' + key + '">'
                              , '<td>' + files[key].name + ' </td>'
                              , '<td>' + (files[key].size / 1014 / 1024).toFixed(1) + 'MB</td>'
                              , '<td>等待上传</td>','</tr>'].join(''));
                            demoListView.append(tr);
                        }
                    }
                    , before: function (obj) {
                        loadingIndex = layer.load(1, {
                            shade: [0.5, '#000']
                        });
                    }
              , done: function (res, index, upload) {
                  if (res.res == "success") { //上传成功
                     // alert($('#Category').combobox('getValue'));
                      com.ajax({
                          url: '/ZY/Train/Upload',
                          data: { ID: res.info.ID, visible: $('#visible input[name="visible"]:checked').val(), download: $('#download input[name="download"]:checked').val(), Category: $('#Category').combobox('getValue') },
                          showLoading:false,
                          success: function (data) {

                          }
                      });
                      var tr = demoListView.find('tr#upload-' + index)
                      , tds = tr.children();
                      tds.eq(2).html('<span style="color: #5FB878;">上传成功</span>');
                      tds.eq(3).html(''); //清空操作
                      return delete this.files[index]; //删除文件队列已经上传成功的文件
                  }
                  else {
                      this.error(index, upload);
                  }
              },
                    error: function (index, upload) {
                        var tr = demoListView.find('tr#upload-' + index)
                        , tds = tr.children();
                        tds.eq(2).html('<span style="color: #FF5722;">上传失败</span>');
                        tds.eq(3).find('.demo-reload').removeClass('layui-hide'); //显示重传
                        console.log();
                    },
                    allDone: function (obj) {
                        layer.close(loadingIndex);
                        window.parent.location.reload();
                    }
                });
            form.render();
        });
    });
</script>
<form class="layui-form" action="">
    <div class="layui-form-item" pane="">
        <label class="layui-form-label">可见</label>
        <div class="layui-input-block" id="visible">
            <input type="radio" name="visible" value="0" title="仅自己可见">
            <input type="radio" name="visible" value="1" title="仅校区可见">
            <input type="radio" name="visible" value="2" title="全部可见" checked="">
        </div>
    </div>
    <div class="layui-form-item" pane="">
        <label class="layui-form-label">下载</label>
        <div class="layui-input-block" id="download">
            <input type="radio" name="download" value="0" title="允许下载" checked="">
            <input type="radio" name="download" value="1" title="禁止下载">
        </div>
    </div>
    <div class="layui-form-item" pane="">
        <label class="layui-form-label">文件类别</label>
        <div class="layui-input-block" id="Category1">
            <input id="Category" name="Category" style="width:150px" class="easyui-combobox" data-options="valueField:'value',textField:'text',data:StaticCombo.Category,panelHeight:'auto',editable:false,required:true" />
        </div>
    </div>
</form>
<div class="layui-upload">
    <button type="button" class="layui-btn layui-btn-normal" id="testList">选择多文件</button>
    <button type="button" class="layui-btn" id="testListAction">开始上传</button>
    <div class="layui-upload-list">
        <table class="layui-table" style="width:580px">
            <thead>
                <tr>
                    <th>文件名</th>
                    <th>大小</th>
                    <th>状态</th>
                    @*<th>操作</th>*@
                </tr>
            </thead>
            <tbody id="demoList"></tbody>
        </table>
    </div>
</div>
